﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DataUpload;
using Logistics;
using Logistics.Utils;

namespace logistics.WinForm
{
    public partial class RegeditWin : Form
    {
        public RegeditWin()
        {
            InitializeComponent();
        }
        private void btnRegedit_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbUser.Text.ToString()) || String.IsNullOrEmpty(tbPsd.Text.ToString()))
            {
                MessageBox.Show("请输入完整的注册信息!");
            }
            else
            {
                Regedit();
            }
        }

        private void Regedit() {
            //判断网络是否连接
            if (!NetworkUtils.IsNetworkConnected())
            {
                MessageBox.Show("请连接网络，提交注册!");
            }
            else
            {
                string rgtResult = "";
                try
                {
                    rgtResult = RegistrationBase.ApplicationRegedit(tbUser.Text.ToString(), tbPsd.Text.ToString(), tbRemark.Text.ToString());
                }
                catch(Exception ex)
                {
                    MessageBox.Show("注册失败，详细信息：" + ex.ToString());
                    tbUser.Text = "";
                    tbPsd.Text = "";
                    tbRemark.Text = "";
                }
                if (String.Equals(rgtResult ,"1"))//申请成功
                {
                    //修改配置文件
                    string localFile = GlobalObjects.ConfigFileLocation;
                    string modifyNode = "/system/SecurityCheck/ApplicationRegedit/IsApplication";
                    RegistrationBase.ModifyXmlNode(localFile, modifyNode, "", "true");
                    MessageBox.Show("注册成功,请等待审核!");
                    this.Close();
                }
                else if (String.Equals(rgtResult, "-2"))//用户不存
                {
                    MessageBox.Show("账户不存在,请填写正确的用户名和密码!");
                    tbUser.Text = "";
                    tbPsd.Text = "";
                    tbRemark.Text = "";
                }
                else if (String.Equals(rgtResult, "-1"))//用户停用
                {
                    MessageBox.Show("账户已停用,请与管理员联系!");
                    tbUser.Text = "";
                    tbPsd.Text = "";
                    tbRemark.Text = "";
                }
                else
                {
                    MessageBox.Show(rgtResult);
                    tbUser.Text = "";
                    tbPsd.Text = "";
                    tbRemark.Text = "";
                }
            }
        }
        private void btnCanncel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
